home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / CLIPBOAR.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  159 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Implementation of TClipboard which provides clipboard encapsulation
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_CLIPBOAR_H)
  11. # include <owl/clipboar.h>
  12. #endif
  13.  
  14. OWL_DIAGINFO;
  15.  
  16. #if defined(OWL2_COMPAT)
  17. //
  18. // Global clipboard object obtained using GetClipboard(). This technique
  19. // is obsolete.
  20. //
  21. // The recomended way is to construct a TClipboard object using the
  22. // TClipboard(HWND) ctor below
  23. //
  24. TClipboard TClipboard::TheClipboard;
  25. #endif
  26.  
  27. const char* TClipboard::DefaultProtocol = "StdFileEditing";
  28.  
  29. //
  30. // Constructs a clipboard object to grab the clipboard given a window handle.
  31. // This is the preferred method of getting the clipboard;
  32. //
  33. // Throws an exception on open failure if mustOpen is true (default)
  34. // mustOpen can be passed as false for compatability
  35. //
  36. TClipboard::TClipboard(HWND hWnd, bool mustOpen)
  37. {
  38.   OpenClipboard(hWnd);
  39.   if (mustOpen && !IsOpen)
  40.     throw TXClipboard(IDS_CLIPBOARDBUSY);
  41. }
  42.  
  43. //
  44. // Destruct a clipboard object & close the clipboard if open
  45. //
  46. TClipboard::~TClipboard()
  47. {
  48.   if (IsOpen)
  49.     ::CloseClipboard();
  50. }
  51.  
  52. //
  53. // Close the clipboard iff it is open
  54. //
  55. void
  56. TClipboard::CloseClipboard()
  57. {
  58.   if (IsOpen) {
  59.     ::CloseClipboard();
  60.     IsOpen = false;
  61.   }
  62. }
  63.  
  64. //
  65. // Open the clipboard
  66. //
  67. bool
  68. TClipboard::OpenClipboard(HWND hWnd)
  69. {
  70.   return IsOpen = ::OpenClipboard(hWnd) != 0;
  71. }
  72.  
  73. //----------------------------------------------------------------------------
  74.  
  75. //
  76. // Construct an available format iterator for a clipboard.
  77. //
  78. #if __DEBUG >= 1
  79. TClipboardFormatIterator::TClipboardFormatIterator(const TClipboard& clip)
  80. #else
  81. TClipboardFormatIterator::TClipboardFormatIterator(const TClipboard& /*clip*/)
  82. #endif
  83. {
  84.   PRECONDITION(bool(clip));
  85.   Restart();
  86. }
  87.  
  88. //
  89. // Restart the format iterator.
  90. //
  91. void
  92. TClipboardFormatIterator::Restart()
  93. {
  94.   _Current = ::EnumClipboardFormats(0);
  95. }
  96.  
  97. //
  98. // Get the next available format.
  99. //
  100. uint
  101. TClipboardFormatIterator::operator ++()
  102. {
  103.   return _Current = ::EnumClipboardFormats(_Current);
  104. }
  105.  
  106. //
  107. // Get the previous format.
  108. //
  109. uint
  110. TClipboardFormatIterator::operator ++(int)
  111. {
  112.   uint current = _Current;
  113.   _Current = ::EnumClipboardFormats(_Current);
  114.   return current;
  115. }
  116.  
  117. //----------------------------------------------------------------------------
  118.  
  119. //
  120. // Create the TXClipboard exception with a string resource.
  121. //
  122. TXClipboard::TXClipboard(uint resId)
  123. :
  124.   TXOwl(resId)
  125. {
  126. }
  127.  
  128.  
  129. //
  130. // Clone the exception for safe throwing in Windows.
  131. //
  132. #if defined(BI_NO_COVAR_RET)
  133. TXBase*
  134. #else
  135. TXClipboard*
  136. #endif
  137. TXClipboard::Clone()
  138. {
  139.   return new TXClipboard(*this);
  140. }
  141.  
  142. //
  143. // Throw the exception.
  144. //
  145. void
  146. TXClipboard::Throw()
  147. {
  148.   THROW( *this );
  149. }
  150.  
  151. //
  152. // Throw the exception.
  153. //
  154. void
  155. TXClipboard::Raise(uint resourceId)
  156. {
  157.   TXClipboard(resourceId).Throw();
  158. }
  159.